package com.example.practicespring.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import static com.example.practicespring.ConstantConfig.ConstantConfig.imgPath;

@Configuration
public class SaTokenConfig implements WebMvcConfigurer {



    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        // 商品图片等定义静态资源映射
        registry.addResourceHandler("/images/**").addResourceLocations("file:" + imgPath);

        // 系统公告文件图片地址映射
        registry.addResourceHandler("/noticeImg/**").addResourceLocations("file:" + "D:\\888888\\notice\\");
    }

     // 注册 Sa-Token 拦截器，打开注解式鉴权功能
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 Sa-Token 拦截器，打开注解式鉴权功能
        registry.addInterceptor(new SaInterceptor()).addPathPatterns("/**").excludePathPatterns("/demo/user/login");;
    }

}
